﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;

namespace SZ
{
    public partial class UpdateControlPoints : Form
    {
        public UpdateControlPoints()
        {
            InitializeComponent();
            this.richTextBox1.AppendText("点号" + "\n");
        }

        private void updateBtn_Click(object sender, EventArgs e)
        {
            //连接sde数据库
            IWorkspace pWorkspace;
            ConnectSDE connectSde = new ConnectSDE();
            pWorkspace = connectSde.SdeWorkspace();

            IFeatureWorkspace pFeatureWorkspace;
            pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
            IFeatureClass pFeatureClass;
            pFeatureClass = pFeatureWorkspace.OpenFeatureClass("SDE.ControlPoints");

            IFeatureCursor pFeatureCursor;
            pFeatureCursor = pFeatureClass.Search(null, false);
            IFeature pFeature;
            pFeature = pFeatureCursor.NextFeature();
            while (pFeature != null)
            {
                if (pFeature.get_Value(1).ToString() == textEdit1.Text)
                {
                    int t = 0;
                    t = pFeature.Table.FindField(comboBoxEdit1.Text);
                    pFeature.set_Value(t, textEdit2.Text);
                    pFeature.Store();
                    string s = pFeature.get_Value(t).ToString();
                    
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
                    MessageBox.Show("更新成功！");
                    this.richTextBox1.AppendText ( pFeature.get_Value(1).ToString());
                    this.comboBoxEdit1.Text = "";
                    this.textEdit1.Text = "";
                    this.textEdit2.Text = "";
                    this.textEdit3.Text = "";
                   
                    return;
                }
                pFeature = pFeatureCursor.NextFeature();
            }

           

        }

        private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxEdit1.Text == "")
                return;
            IWorkspace pWorkspace;
            ConnectSDE connectSde = new ConnectSDE();
            pWorkspace = connectSde.SdeWorkspace();

            IFeatureWorkspace pFeatureWorkspace;
            pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
            IFeatureClass pFeatureClass;
            pFeatureClass = pFeatureWorkspace.OpenFeatureClass("SDE.ControlPoints");

            IFeatureCursor pFeatureCursor;
            pFeatureCursor = pFeatureClass.Search(null, false);
            IFeature pFeature;
            pFeature = pFeatureCursor.NextFeature();

            while (pFeature != null)
            {
                if (pFeature.get_Value(1).ToString() == textEdit1.Text)
                {
                    int t = 0;
                    t = pFeature.Table.FindField(comboBoxEdit1.Text);
                    textEdit3.Text = pFeature.get_Value(t).ToString();
                    return;

                }
                pFeature = pFeatureCursor.NextFeature();
            }

        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
